import React from 'react';
import { createRoot } from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import DevToolbar from './components/DevToolbar';

// Get the root element
const rootElement = document.getElementById('root');
if (!rootElement) throw new Error('Failed to find the root element');

// Create a root
const root = createRoot(rootElement);

// Render the main app
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

// Create a separate root for the DevToolbar to avoid interfering with the main app
if (process.env.NODE_ENV === 'development') {
  // Create a container for the toolbar
  const toolbarContainer = document.createElement('div');
  toolbarContainer.id = 'dev-toolbar-container';
  document.body.appendChild(toolbarContainer);

  // Create a root for the toolbar
  const toolbarRoot = createRoot(toolbarContainer);
  
  // Render the toolbar
  toolbarRoot.render(
    <DevToolbar config={{ plugins: [] }} />
  );
}

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();


